Hi,
When walking through a module, i.e.
Module m = current
Object o = null
for o in all m do {
...
}
How do I detect within the loop that I've reached the last object of the module?
Thanks,
/ Carsten
SystemAdmin - Mon May 11 04:44:56 EDT 2009 |
|
Re: Detecting that I'm at the last object in module Peter_Albert - Mon May 11 05:02:49 EDT 2009
Generally, the loop stops at the last object, hence there is nothing particular for you to do. But the different 'for object in ...' loops stop at different definitions of "last object in module". In your example, the object o after your loop is a handle to the last visible object in the module, which might be a deleted object, if deleted objects are visible.
The same object would be the return value of the 'Object last(Module m)' perm
Assuming that you are interested in the last undeleted object in the module, independent of whether it is visible in the current view, you would use
Module mod = current
Object obj
for obj in entire mod do
{
if (isDeleted obj){continue}
}
print "Object " obj."Absolute Number" " is the last undeleted object in module " name mod "."
If a table happens to appear at the very bottom of your module, and you want to exclude the table and instead get the last object before the table, you would have to include
if (table obj){continue}
if (row obj){continue}
if (cell obj){continue}
in the loop boy.
Regards,
Peter
|
|
Re: Detecting that I'm at the last object in module SystemAdmin - Mon May 11 05:29:13 EDT 2009 Peter_Albert - Mon May 11 05:02:49 EDT 2009
Generally, the loop stops at the last object, hence there is nothing particular for you to do. But the different 'for object in ...' loops stop at different definitions of "last object in module". In your example, the object o after your loop is a handle to the last visible object in the module, which might be a deleted object, if deleted objects are visible.
The same object would be the return value of the 'Object last(Module m)' perm
Assuming that you are interested in the last undeleted object in the module, independent of whether it is visible in the current view, you would use
Module mod = current
Object obj
for obj in entire mod do
{
if (isDeleted obj){continue}
}
print "Object " obj."Absolute Number" " is the last undeleted object in module " name mod "."
If a table happens to appear at the very bottom of your module, and you want to exclude the table and instead get the last object before the table, you would have to include
if (table obj){continue}
if (row obj){continue}
if (cell obj){continue}
in the loop boy.
Regards,
Peter
Thanks for the hint on all vs. entire; I had overlooked that part.
But to return to the original question: For the exporter I'm writing, I do want to know when I'm at the last object. If I'm not, I want to emit a page break. If I am, I don't want to.
So the question remains: How do I detect that I'm at the last object?
|
|
Re: Detecting that I'm at the last object in module Peter_Albert - Mon May 11 05:39:44 EDT 2009 SystemAdmin - Mon May 11 05:29:13 EDT 2009
Thanks for the hint on all vs. entire; I had overlooked that part.
But to return to the original question: For the exporter I'm writing, I do want to know when I'm at the last object. If I'm not, I want to emit a page break. If I am, I don't want to.
So the question remains: How do I detect that I'm at the last object?
Well, first get the last object and then check during the export loop:
Module mod = current Module
Object lastObj = null
Object obj
for obj in entire mod do
{if (isDeleted obj){continue}}
lastObj = obj
for obj in entire mod do
{
// do your export stuff here
if (obj != lastObj)
{
// add page break
}
}
Regards,
Peter
|
|
Re: Detecting that I'm at the last object in module SystemAdmin - Mon May 11 07:50:12 EDT 2009 Peter_Albert - Mon May 11 05:39:44 EDT 2009
Well, first get the last object and then check during the export loop:
Module mod = current Module
Object lastObj = null
Object obj
for obj in entire mod do
{if (isDeleted obj){continue}}
lastObj = obj
for obj in entire mod do
{
// do your export stuff here
if (obj != lastObj)
{
// add page break
}
}
Regards,
Peter
Thanks!
I had already figured that as a way to go, but thought there'd be a more elegant/intuitive way to do it.
|
|
Re: Detecting that I'm at the last object in module adevicq - Mon May 11 08:11:13 EDT 2009
Hi,
... or you can put your page break before:
bool bFirst = true
for o in m do
{
if (!bFirst)
{
page break here
}
bfirst = false
export code here
}
this way, you don't need to detect the last object...
|
|
Re: Detecting that I'm at the last object in module dpechacek - Mon May 11 10:02:24 EDT 2009 adevicq - Mon May 11 08:11:13 EDT 2009
Hi,
... or you can put your page break before:
bool bFirst = true
for o in m do
{
if (!bFirst)
{
page break here
}
bfirst = false
export code here
}
this way, you don't need to detect the last object...
Or just use the Object last(Module m) function...
AAI Services, Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
|
|
Re: Detecting that I'm at the last object in module SystemAdmin - Tue May 12 09:26:32 EDT 2009 dpechacek - Mon May 11 10:02:24 EDT 2009
Or just use the Object last(Module m) function...
AAI Services, Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
That'd be the ticket, except that (if I read the documentation correctly), this function respects the current view settings, which is not useful for me.
|
|
Re: Detecting that I'm at the last object in module dpechacek - Wed May 13 09:06:44 EDT 2009 SystemAdmin - Tue May 12 09:26:32 EDT 2009
That'd be the ticket, except that (if I read the documentation correctly), this function respects the current view settings, which is not useful for me.
Module m = current Module;
Filter f = current Filter
filtering(off);
Object o = last(m);
set(m,f);
filtering(on);
AAI Services, Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
|
|
Re: Detecting that I'm at the last object in module dpechacek - Wed May 13 09:09:53 EDT 2009 dpechacek - Wed May 13 09:06:44 EDT 2009
Module m = current Module;
Filter f = current Filter
filtering(off);
Object o = last(m);
set(m,f);
filtering(on);
AAI Services, Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Also your original loop you posted also respects the current display set so if that's the loop you're using it wouldn't be an issue.
If you were doing a loop to not respect the current display set, you'd need to do +italics+for o in entire(m) do {+italics+.
AAI Services, Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
|
|
Re: Detecting that I'm at the last object in module dpechacek - Wed May 13 09:10:58 EDT 2009 dpechacek - Wed May 13 09:09:53 EDT 2009
Also your original loop you posted also respects the current display set so if that's the loop you're using it wouldn't be an issue.
If you were doing a loop to not respect the current display set, you'd need to do +italics+for o in entire(m) do {+italics+.
AAI Services, Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
And I messed up that Italics thing huh....
AAI Services, Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
|
|
Re: Detecting that I'm at the last object in module tommy3824 - Fri May 15 11:02:03 EDT 2009 SystemAdmin - Tue May 12 09:26:32 EDT 2009
That'd be the ticket, except that (if I read the documentation correctly), this function respects the current view settings, which is not useful for me.
What exactly are the trying to find then? The newest object created or the object at the bottom of the module not based on a defined view.
For 1 you can do...
Module m = current
Object o = null
Object o_last = null
int abs_max = 0
int abs = 0
for o in m do
{
abs = o."Absolute Number"
if(abs > abs_max)
{
abs_max = abs
o_last = object abs
}
}
and for 2 can be ...
Module m = current
Object o_last = null
string defView = getDefaultViewForModule m
load view "Standard view"
o_last = last m
if(!null defView)
load view (defView)
or what dpechacek posted
|
|
Re: Detecting that I'm at the last object in module djakad - Mon May 18 18:53:14 EDT 2009
I think you can run on the idea of adding the page break first, and simply not adding a page break for the first object:
Module m = current
Object o = null
bool xFirst = true
for o in entire(m) do {
if(xFirst) {
// don't add page break
xFirst = false
} else {
// add page break
}
exportObject(o)
}
Be aware that the "for Object in entire(Module)" loop also includes all deleted objects. You can weed these out by adding something like "if(!isDeleted(o)) {doExport(o)}
|
|